#include "cpu/exec/template-start.h"

#define instr or

static void do_execute () {
	// DATA_TYPE result = op_dest->val | op_src->val;
	// OPERAND_W(op_dest, result);
	//手动实现写回
	DATA_TYPE result;
	switch (op_src->type) {
		case OP_TYPE_REG:
			switch (op_src->reg) {
				case 0: op_src->val = cpu.eax; break;
				case 1: op_src->val = cpu.ecx; break;
				case 2: op_src->val = cpu.edx; break;
				case 3: op_src->val = cpu.ebx; break;
				case 4: op_src->val = cpu.esp; break;
				case 5: op_src->val = cpu.ebp; break;
				case 6: op_src->val = cpu.esi; break;
				case 7: op_src->val = cpu.edi; break;
				default: assert(0);

			}
			break;
		case OP_TYPE_MEM:
			op_src->val = swaddr_read(op_src->addr, DATA_BYTE);
			break;
		default: assert(0);
	}
	switch (op_dest->type) {
		case OP_TYPE_REG:
			switch (op_dest->reg) {
				case 0: op_dest->val = cpu.eax; break;
				case 1: op_dest->val = cpu.ecx; break;
				case 2: op_dest->val = cpu.edx; break;
				case 3: op_dest->val = cpu.ebx; break;
				case 4: op_dest->val = cpu.esp; break;
				case 5: op_dest->val = cpu.ebp; break;
				case 6: op_dest->val = cpu.esi; break;
				case 7: op_dest->val = cpu.edi; break;
				default: assert(0);

			}
			break;
		case OP_TYPE_MEM:
			op_dest->val = swaddr_read(op_dest->addr, DATA_BYTE);
			break;
		default: assert(0);	
	}
	result = op_dest->val | op_src->val;
	switch (op_dest->type) {
		case OP_TYPE_REG:
			switch (op_dest->reg) {
				case 0: cpu.eax = result; break;
				case 1: cpu.ecx = result; break;
				case 2: cpu.edx = result; break;
				case 3: cpu.ebx = result; break;
				case 4: cpu.esp = result; break;
				case 5: cpu.ebp = result; break;
				case 6: cpu.esi = result; break;
				case 7: cpu.edi = result; break;
				default: assert(0);

			}
			break;
		case OP_TYPE_MEM:
			swaddr_write(op_dest->addr, DATA_BYTE, result);
			break;
		default: assert(0);
	}
	//设置标志位
	cpu.eflags.OF = 0;
	cpu.eflags.CF = 0;

        // update_eflags_pf_zf_sf((DATA_TYPE_S)result);
        cpu.eflags.CF = cpu.eflags.OF = 0;

	print_asm_template2();
}

make_instr_helper(i2a)
make_instr_helper(i2rm)
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(si2rm)
#endif
make_instr_helper(r2rm)
make_instr_helper(rm2r)

#include "cpu/exec/template-end.h"
